<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/common/taglibs.jsp" %>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="${ctx}/lib/bootstrap-3.3.7-dist/css/bootstrap.css"/>
	</head>
	<body>
		<!-- 导航 开始 -->
		<nav class="navbar navbar-default">
		  <div class="container">
		    <!-- Brand and toggle get grouped for better mobile display -->
		    <div class="navbar-header">
		      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
		        <span class="sr-only">Toggle navigation</span>
		        <span class="icon-bar"></span>
		        <span class="icon-bar"></span>
		        <span class="icon-bar"></span>
		      </button>
		      <a class="navbar-brand" href="#">教务管理系统</a>
		    </div>
		
		    <!-- Collect the nav links, forms, and other content for toggling -->
		    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
		      <ul class="nav navbar-nav">
		        <li class="active"><a href="student_list.html"><span class="glyphicon glyphicon-home" aria-hidden="true"></span>&nbsp;&nbsp;&nbsp;学生管理</a></li>
		        <li><a href="banji_list.html"><span class="glyphicon glyphicon-user" aria-hidden="true"></span>&nbsp;&nbsp;&nbsp;班级管理</a></li>
		        <li><a href="#"><span class="glyphicon glyphicon-list" aria-hidden="true"></span>&nbsp;&nbsp;&nbsp;课程管理</a></li>
		        <li><a href="#"><span class="glyphicon glyphicon-calendar" aria-hidden="true"></span>&nbsp;&nbsp;&nbsp;教务管理</a></li>
		        <li><a href="${ctx}/online_user_list.jsp"><span class="glyphicon glyphicon-calendar" aria-hidden="true"></span>&nbsp;&nbsp;&nbsp;在线管理员</a></li>
		      </ul>
		      <ul class="nav navbar-nav navbar-right">
		        <li><a href="${ctx}/login?method=logout"> 欢迎：${user.name} <span class="glyphicon glyphicon-off" aria-hidden="true"></span>&nbsp;&nbsp;&nbsp;退出</a></li>
		      </ul>
		    </div><!-- /.navbar-collapse -->
		  </div><!-- /.container-fluid -->
		</nav>
		<!-- 导航 结束  -->
		
		<!-- 内容部分 开始 -->
		<div class="container">
			<div class="row">
				<!-- 左边部分 开始 -->
				<div class="col-md-2">
					<div class="list-group">
					  <a href="student_list.html" class="list-group-item active">
					    学生列表
					  </a>
					  <a href="javascript:insert()" class="list-group-item">学生添加</a>
				</div>
				</div>
				<!-- 左边部分 结束 -->
				
				<!-- 右边部分 开始 -->
				<div class="col-md-10">
					<form action="${ctx}/student/pageList.action"
						 id="searchFrom"  method="POST">
						<input type="hidden" id="pageNo" name="pageNo"/>
						姓名：<input type="text" name="name" value="${searchCondition.name}"/>
						年龄：<input type="text" name="age" value="${searchCondition.age}"/>
						性别：<select id="searchGender" name="gender">
								<option value="">不限</option>
								<option value="男">男</option>
								<option value="女">女</option>
							 </select>
						<input type="submit" value="搜索">
					</form>
					<br/> 
					<table class="table table-hover">
						<tr>
							<th>#</th>
							<th>名字</th>
							<th>年龄</th>
							<th>性别</th>
							<th>班级</th>
							<th>删除</th>
						</tr>
						<c:forEach items="${pageBean.list}" var="map">
							<tr>
								<td>${map['s_id']}</td>
								<td>${map['s_name']}</td>
								<td>${map['s_age']}</td>
								<td>${map['s_gender']}</td>
								<td>${map['b_name']}</td>
								<td><a href="javascript:deleteById(${map['s_id']})">删除</a></td>
							</tr>
						</c:forEach>
					</table>
					<ul class="pagination">
						<c:forEach begin="1" end="${pageBean.totalPage}" var="page">
							<c:if test="${pageBean.pageNo==page}">
								<li class="active"><a href="#">${page}</a></li>
							</c:if>
							<c:if test="${pageBean.pageNo!=page}">
								<li><a href="javascript:goPage(${page})">${page}</a></li>
							</c:if>
						</c:forEach>
					</ul>
				</div>
				<!-- 右边部分 结束 -->
			</div>
			
		</div>
		<!-- 内容部分 结束 -->
		
		<script src="${ctx}/lib/jquery/jquery-1.11.1.js" type="text/javascript" charset="utf-8"></script>
		<script src="${ctx}/lib/bootstrap-3.3.7-dist/js/bootstrap.js" type="text/javascript" charset="utf-8"></script>
		<script src="${ctx}/lib/layer/layer.js" type="text/javascript" charset="utf-8"></script>
		<script src="${ctx}/js/mylayer.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			function goPage(page) {
				$("#pageNo").val(page);
				$("#searchFrom").submit();
			}
			
			$(function() {
				var options = $("#searchGender option:gt(0)");
				for(var i = 0; i < options.length; i++) {
					if (options[i].value == "${searchCondition.gender}") {
						$(options[i]).prop("selected", true);
					}
				}
			});
			
			function doSearch() {
				var searchName = $("#searhName").val();
				location.href="${ctx}/student?method=pageList&searchName=" + searchName;
			}
			
			function deleteById(id) {
				//mylayer.confirm("您确认要删除么？", "${ctx}/student/deleteById.action?id=" + id);
				layer.confirm(
					"您确定要删除么",
					function(index) {
						console.log("点击了确定");
						//location.href = url;
						//layer.close(index);
						$.post(
							"${ctx}/student/deleteById.action?id=" + id,
							function(data) {
								if(data) {
									mylayer.success("删除成功");
									location.reload();
								} else {
									mylayer.errorMsg("删除失败");
								}
							},
							"json"
						);
					},
					function(index) {
						console.log("点击了取消");
					}
				);
			}
			
			function insert() {
				layer.open({
					type : 2, // iframe
					title : "添加学生",
					area : ["260px", "200px"], // 弹出框的宽和高
					offset : "100px", //只定义top坐标，水平保持居中
					content : "${ctx}/student/getInsertPage.action"
				});
			}
		</script>
	</body>
</html>
